//
//  TIntColorTestView.swift
//  EasySwift
//
//  Created by 王隆帅 on 2017/6/13.
//  Copyright © 2017年 王隆帅. All rights reserved.
//

import UIKit

class TIntColorTestView: UIView {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    
    var label: UILabel;
    
    override init(frame: CGRect) {
        
        self.label = UILabel.init();
        super.init(frame: frame);
        
        self.testTintColor();
    }
    
    required init?(coder aDecoder: NSCoder) {
        
        self.label = UILabel.init();
        super.init(coder: aDecoder);
        fatalError("init(coder:) has not been implemented")
    }
    
    
    // test tintColor
    func testTintColor() {
//        
        print("normal ----- \(self.tintAdjustmentMode.rawValue)");
        print("normal ----- \(self.tintColor)");

        self.tintAdjustmentMode = .dimmed;
        
        print("dimmd ----- \(self.tintAdjustmentMode.rawValue)");
        print("dimmd ----- \(self.tintColor)");
        
        self.label.frame = CGRect.init(x: 30, y: 80, width: 250, height: 50);
        self.label.text = "这是王隆帅的label";
        self.label.textColor = self.tintColor;
        self.addSubview(self.label);
        
        let button = UIButton.init(type: .system);
        button.frame = CGRect.init(x: 30, y: 140, width: 250, height: 50);
        button.addTarget(self, action: #selector(btnClick), for: .touchUpInside)
        button.setTitle("这是王隆帅的btn", for: .normal);
        button.tintAdjustmentMode = .normal;

        self.addSubview(button);
        
        var image = UIImage.init(named: "imageToColor");
        image = image?.withRenderingMode(.alwaysTemplate);
        let imageView = UIImageView.init(frame: CGRect.init(x: 30, y: 200, width: 250, height: 50));
        imageView.image = image;
        imageView.tintAdjustmentMode = .automatic;
        self.addSubview(imageView);
        
    }
    
    func btnClick() {
        
        self.tintColor = UIColor.init(red: CGFloat(Double(arc4random() % 255) / 255.0), green: CGFloat(Double(arc4random() % 255) / 255.0), blue: CGFloat(Double(arc4random() % 255) / 255.0), alpha: 1.0);
    }
    
    
    
    override func tintColorDidChange() {
        
        self.label.textColor = self.tintColor;
    }

}
